﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static 实验二._4.Sun;

namespace 实验二._4
{
    class Program
    {
        static void Main(string[] args)
        {
            Cock cock = new Cock("花花");
            Host host = new Host("小明");
            host.foster(cock);
            Dog dog = new Dog("狗");
            dog.Owner = host;
            Cat cat = new Cat("猫");
            cat.Owner = host;
            Sun.rise();
            Console.ReadKey();
        }
    }
    public static class Sun
    {

        public static event EventHandler onrise;//EventHandler是一个无事件数据的方法，定义onrise为太阳升起事件
        public static void rise()//调用onrise
        {
            Console.WriteLine("太阳从东方升起...");
            if (onrise != null)
                onrise(null, null);
        }

    }
    public class Cock//公鸡类
    {
        private string name;
        public Cock(string name)//构造函数中联系太阳升起事件和
        {
            this.name = name;
            Sun.onrise += new EventHandler(Sun_onrise);
        }
        private void Sun_onrise(object sender, EventArgs e)//处理太阳升起事件（onrise）的方法
        {
            Console.WriteLine("公鸡{0}:", name);
            Console.WriteLine("雄鸡一唱天下白");
            this.sing();
        }
        public event EventHandler Onsing;//定义onsing 为鸡鸣事件
        public void sing()//调用onsing
        {
            Console.WriteLine("喔哦哦哦哦哦...");
            if (Onsing != null)
                Onsing(null, null);
        }
    }
    public class Host//主人类
    {
        private string name;
        public Host(string name)
        {
            this.name = name;
        }
        public string getname()
        {
            return name;
        }
        public event EventHandler Ongetup;//定义主人起床事件
        public void Getup()//调用ongetup
        {
            Console.WriteLine("日出而作...");
            if (Ongetup != null)
                Ongetup(this, null);

        }
        public void foster(Cock c)
        {
            c.Onsing += new EventHandler(c_Onsing);//联系鸡鸣时间和处理鸡鸣事件的方法

        }
        private void c_Onsing(object sender, EventArgs e)//处理鸡鸣方法
        {
            Console.WriteLine("主人{0}:", name);
            Console.WriteLine("闻鸡起舞！");
            Getup();

        }
    }
    public class Dog//狗类
    {
        private string name;
        public Dog(string name)
        {
            this.name = name;
        }
        private Host owner;

        public Host Owner
        {
            get { return owner; }
            set
            {
                owner = value;
                value.Ongetup += new EventHandler(owner_getup);//联系事件和事件处理方法
            }
        }
        public void owner_getup(object sender, EventArgs e)//处理主人起床方法
        {
            Console.WriteLine("旺旺");
        }
    }
    public class Cat//猫类
    {
        private string name;
        public Cat(string name)
        {
            this.name = name;
        }
        private Host owner;

        public Host Owner
        {
            get { return owner; }
            set
            {
                owner = value;
                value.Ongetup += new EventHandler(owner_getup);//联系事件和事件处理方法
            }
        }
        public void owner_getup(object sender, EventArgs e)//处理主人起床方法
        {
            Console.WriteLine("喵喵");
        }
    }
}
